﻿<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>网站管理</title>
<!--#include file="conn.asp"-->
<meta name="" content="" />
<style type="text/css">
* {margin:0;padding:0;list-style:none;}
html {overflow-y:auto!important;*overflow-y:scroll;}
body{scrollbar-base-color: #F8F8F8;scrollbar-arrow-color: #698CC3;font-size: 12px;background-color: #fff;font-family: "微软雅黑";margin:5px;}
a{text-decoration: none;}a:hover{ text-decoration: underline;} 
textarea,input,select{ font-family: "微软雅黑"; font-size: 12px;  color: #000000; font-weight: normal; background-color: #EAFCD5;}
li {list-style-type:none;}.clear{clear:both;}
textarea {width:80%;height:50px;}.textarea{height:250px;}
.text{width:80%;height:20px;}.input{width:250px;}.button{width:50px;}
.table{background-color:#E2F4FC;}.table ul{padding-left:5%;}
.liebiao {position: relative;}
.liebiao ul {overflow:hidden;line-height:30px;display: block;width: 100%;margin: 0 auto;position: relative;}
.liebiao ul li{float:left;width:10%;padding-left:5%;}
.liebiao ul li.different{width:50%;}.liebiao ul:hover {background:#E2F4FC}
.page{PADDING:8px; MARGIN: 3px;  TEXT-ALIGN: center; clear:both;}
.page a{ border:#01B0ED 1px solid; padding:2px 5px; margin:2px; color:#01B0ED; text-decoration:none;}
.page a:hover{color:#FFFFFF; background:#01B0ED;text-decoration:none;}
.page span.current {border:#01B0ED 1px solid;padding:2px 5px; margin:2px;color: #333333;background:#01B0ED;}
.page span{border:#F6F6F6 1px solid;padding:2px 5px; margin:2px;color:#333333;}
.add{TEXT-ALIGN: center;}.add li {padding-top:20px;}
.submit_button{width:90px;height:30px;background-color: #068dbf;background-repeat: no-repeat;color:#ffffff;font-weight:bold;}
</style>
</head>

<body>
<%
dim id,keywords,action
id=trim(request("id"))
keywords=trim(request("keywords"))

if trim(request("page"))<>"" then
page=trim(request("page"))
else
page=1
end if

if trim(request("pagesize"))<>"" then
pagesize=trim(request("pagesize"))
else
pagesize=2'默认一页显示数
end if
%>
<%
if request("action")="edit" then
call edit()
elseif request("action")="savenew" then
call savenew()
elseif request("action")="savedit" then
call savedit()
elseif request("action")="delAll" then
call delAll()
else
call List()
end if

sub List()
%>
<div class="table">

<form name="form1" method="get" action="index.asp">
<ul>
<li>
搜索：
<input name="keywords" type="text" id="keywords" value="<%=keywords%>" class="input">
<input type="submit" name="Submit" value="搜索" class="button">

<select name="jumpMenu_pagesize" id="jumpMenu_pagesize" onChange="location=this.options[this.selectedIndex].value" >
<option value="index.asp?page=1&amp;pagesize=02&amp;keywords=<%=keywords%>" <% if pagesize="02" then %>selected<% end if %>>每页【02】条记录</option>
<option value="index.asp?page=1&amp;pagesize=10&amp;keywords=<%=keywords%>" <% if pagesize="10" then %>selected<% end if %>>每页【10】条记录</option>
<option value="index.asp?page=1&amp;pagesize=20&amp;keywords=<%=keywords%>" <% if pagesize="20" then %>selected<% end if %>>每页【20】条记录</option>
<option value="index.asp?page=1&amp;pagesize=50&amp;keywords=<%=keywords%>" <% if pagesize="50" then %>selected<% end if %>>每页【50】条记录</option>
<option value="index.asp?page=1&amp;pagesize=90&amp;keywords=<%=keywords%>" <% if pagesize="90" then %>selected<% end if %>>每页【90】条记录</option>
</select>
</li>
</ul>
</form>
</div>
<div class="clear"></div>

<div class="liebiao">
<form name="myform" method="POST" action="index.asp?action=delAll">

<%
set rs=server.createobject("adodb.recordset")
sql ="select * from news where name like '%"&keywords&"%' order by id desc" 
Rs.Open Sql,Conn,1,1
page=request.QueryString("page")
if Isnumeric(page) then
page=cint(page)
if page<1 then page=1
else
page=1
end if
everypage=pagesize
rs.pagesize=everypage
if rs.bof and rs.eof then
%>
<ul><li>没有数据</li></ul>
<%
else
page_count=rs.pagecount
rs.AbsolutePage=page
j=0
n=1
%>
<% do while not rs.eof and j<rs.pagesize
%>
<ul>
<li><input type="checkbox" value="<%=rs("id")%>" name="id" onClick="unselectall(this.form)" ></li>
<li><input name="pl_id" type="hidden" id="pl_id" value="<%=rs("id")%>"></li>
<li><%=rs("id")%></li>
<li class="different"><%=rs("name")%></li>


<li><a href="index.asp?action=edit&id=<%=rs("id")%>&page=<%=page%>">编辑</a></li>
</ul>
<%if n mod 1=0 then%>
<%end if%>
<%
n=n+1
j=j+1
rs.movenext
loop
end if%>
<ul>
<li><input name="Action" type="hidden"  value="Del">
<input name="chkAll" type="checkbox" id="chkAll" onClick=CheckAll(this.form) value="checkbox" ></li>
<li>
<input name="Del" type="submit" id="Del"  onClick="JavaScript:return confirm('确定删除吗？')" value="批量删除" class="submit_button"></li>
</ul>
</form>
</div>
<div class="clear"></div>
<div class="page"><ul><li>
<span>共<%=rs.recordcount%>条记录</span>
<span><%=page%>/<%=page_count%>页</span>
<%if page=1 then%>
<a>首页</a><a>上一页</a>
<%else%>
<a href="index.asp?page=1&amp;pagesize=<%=pagesize%>&amp;keywords=<%=keywords%>&amp" >首页</a>
<a href="index.asp?page=<%=page-1%>&amp;pagesize=<%=pagesize%>&amp;keywords=<%=keywords%>&amp" >上一页</a>
<%end if%>
<%for j=page-3 to page-1%>
<%if j>0 then%>
<a href="index.asp?page=<%=j%>&amp;pagesize=<%=pagesize%>&amp;keywords=<%=keywords%>&amp"><%=j%></a>
<%end if%>
<%next%>
<%for j=page to page+3%>
<% if j<=page_count then%>
<%if j=page then%>
<span class="current"><%=j%></span>
<%else%>
<a href="index.asp?page=<%=j%>&amp;pagesize=<%=pagesize%>&amp;keywords=<%=keywords%>&amp"><%=j%></a>
<%end if%>
<%end if%>
<% next%>
<%if page<page_count then%>
<a href="index.asp?page=<%=page+1%>&amp;pagesize=<%=pagesize%>&amp;keywords=<%=keywords%>&amp" >下一页</a>
<a href="index.asp?page=<%=page_count%>&amp;pagesize=<%=pagesize%>&amp;keywords=<%=keywords%>&amp" >末页</a>
<%else%>
<a>下一页</a><a>末页</a></li>
<%end if%>
</ul>
<div class="clear"></div>
</div>
<%
rs.close
set rs=nothing
'end sub

'sub add()
%>

<div class="add">
<form action="index.asp?action=savenew" name="myform" method=post>
<ul>
<li><input name="name" type="text" id="name" class="text"></li>
<li><textarea name="img"  id="img"></textarea></li>
<li><textarea name="content" class="textarea"></textarea></li>
<li><input name="Submit" type="submit" value="添 加" class="submit_button"></li>
</ul>
</form>
</div>

<%
end sub

sub savenew()
name=trim(request.form("name"))
img=trim(request.form("img"))
content=trim(request.form("content"))

set rs = server.CreateObject ("adodb.recordset")
sql="select * from news "
rs.open sql,conn,1,3
rs.AddNew

rs("name")=name
rs("img")=img
rs("content")=content

rs.update

rs.close
set rs=nothing

Call Alert ("添加成功！","index.asp")
end sub

sub edit()
id=request("id")
set rs = server.CreateObject ("adodb.recordset")
sql="select * from news where id="& id &""
rs.open sql,conn,1,1
%>

<div class="add">
<form action="index.asp?action=savedit" name="myform" method=post>
<ul>
<li><input name="name" type="text" id="name" value="<%=rs("name")%>" class="text"></li>
<li><textarea name="img" id="img"><%=rs("img")%></textarea></li></ul></li>
<li><textarea name="content"  class="textarea"><%=rs("content")%></textarea></li>
<input name="id" type="hidden" id="id" value="<%=rs("id")%>">
<input name="page" type="hidden" id="page" value="<%=page%>">
<li><input name="Submit" type="submit" value="修 改" class="submit_button"></li>
</ul>
</form>
</div>

<%
end sub

sub savedit()
name=trim(request.form("name"))
img=trim(request.form("img"))
content=trim(request.form("content"))

set rs = server.CreateObject ("adodb.recordset")
sql="select * from news where id="&id&""
rs.open sql,conn,1,3
if not(rs.eof and rs.bof) then

rs("name")=name
rs("img")=img
rs("content")=content

rs.update

Call Alert ("修改成功！","index.asp?page="&page&"")
else
Call Alert ("修改错误！",-2)
end if
rs.close
set rs=nothing
end sub

Sub delAll
If id=""  Then
Call Alert ("请选择记录!","-1")
ElseIf Request("Del")="批量删除" Then
Server.ScriptTimeout=99999999

Dim del_id
del_id=request.form("id")
set rs_del = server.CreateObject ("adodb.recordset")
rs_del.open "select * from [news]  where id In(" & del_id & ")",conn,1,1

sql="delete from [news] where id In(" & del_id & ")"

conn.execute sql

Call Alert ("批量删除成功","index.asp")

End If
End Sub
%>

<script language="javascript" type="text/javascript"  >
function unselectall(thisform){
        if(thisform.chkAll.checked){
            thisform.chkAll.checked = thisform.chkAll.checked&0;
        }   
    }
function CheckAll(thisform){
        for (var i=0;i<thisform.elements.length;i++){
            var e = thisform.elements[i];
            if (e.Name != "chkAll"&&e.disabled!=true)
                e.checked = thisform.chkAll.checked;
        }
    }</script>


<%
conn.close '断开数据库连接
set conn=nothing
%>
</body>
</html>
